package com.qiantu.phone.ui.activity;

import android.view.View;

import com.hjq.http.listener.HttpCallback;
import com.qiantu.api.entity.SmsBean;
import com.qiantu.api.http.LLHttpManager;
import com.qiantu.api.http.model.HttpData;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.app.AppApplication;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class LogOffActivity extends AppActivity {
    private android.widget.CheckBox checkbox;
    private android.widget.TextView btnNext;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_log_off;
    }

    @Override
    protected void initView() {
        checkbox = findViewById(R.id.checkbox);
        btnNext = findViewById(R.id.btn_next);
        setOnClickListener(checkbox, btnNext);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View view) {
        if (view == checkbox){
            btnNext.setEnabled(checkbox.isChecked());
        }else if (view == btnNext){
            getSmsCode();
        }
    }

    private void getSmsCode() {
        showDialog();
        Map<String, Object> data = new HashMap<>();
        data.put("mobile", AppApplication.getInstance().getUserPhone());
        data.put("smsType", "closeAccount_boyun");
        // 隐藏软键盘
        hideKeyboard(getCurrentFocus());
        LLHttpManager.sendSms(this, data, new HttpCallback<HttpData<SmsBean>>(this) {
            @Override
            public void onStart(Call call) {
            }

            @Override
            public void onEnd(Call call) {
                hideDialog();
            }

            @Override
            public void onSucceed(HttpData<SmsBean> data) {
                if (data.isRequestSucceed()) {
                    toast(R.string.sms_code_send);
                    postDelayed(() -> {
                        // 跳转到验证码界面
                        //验证老手机号，传如原smsId
                        Captcha2Activity.start(getAppActivity(), AppApplication.getInstance().getUserPhone(), "closeAccount_boyun", data.getData().getSmsID());
                    }, 600);
                }
            }

            @Override
            public void onFail(Exception e) {
                super.onFail(e);
            }
        });

    }
}